package cn.ddiancan.schedule;

import cn.ddiancan.schedule.base.service.ITaskTimerService;
import cn.ddiancan.schedule.task.CronTaskRegistrar;
import cn.ddiancan.schedule.task.service.DistributedLockService;
import cn.ddiancan.schedule.task.service.SchedulerService;
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

@SpringBootApplication
@EnableDiscoveryClient
public class XddcloudSchedulerApplication {

    @Bean
    public SchedulerService schedulerService(ITaskTimerService taskTimerService, DistributedLockService distributedLockService,
                                             ApplicationContext applicationContext, CronTaskRegistrar cronTaskRegistrar) {
        return new SchedulerService(taskTimerService, distributedLockService, applicationContext, cronTaskRegistrar);
    }

    @Bean
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource dataSource() {
        return new DruidDataSource();
    }

    public static void main(String[] args) {
        SpringApplication.run(XddcloudSchedulerApplication.class, args);
        System.out.println("\033[31m     /\\_/\\");
        System.out.println("\033[31m    / o o \\");
        System.out.println("\033[33m   (   \"   )");
        System.out.println("\033[32m    \\~(*)~/");
        System.out.println("\033[34m      -^-");
        System.out.println("定时服务启动成功");
    }

}
